From e3d0c474a83c3548aa6763561826f71c12a55fe6 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 14 Jun 2004 10:40:24 +0000 Subject: [PATCH] Storing IP in RC. Off by default. Tested: * Installation * Edit when switched off * Edit when switched on --- includes/DefaultSettings.php | 3 ++ includes/RecentChange.php | 68 +++++++++++++++++++++++++----------- maintenance/indexes.sql | 3 +- maintenance/tables.sql | 3 +- maintenance/updaters.inc | 8 +++-- 5 files changed, 61 insertions(+), 24 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 3d7f89f138..0445c4ba4e 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -332,6 +332,9 @@ if( !isset( $wgCommandLineMode ) ) { # Show seconds in Recent Changes $wgRCSeconds = false; +# Log IP addresses in the recentchanges table +$wgPutIPinRC = false; + # RDF metadata toggles $wgEnableDublinCoreRdf = false; $wgEnableCreativeCommonsRdf = false; diff --git a/includes/RecentChange.php b/includes/RecentChange.php index fb385bca24..793cb6b11b 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -21,6 +21,7 @@ mAttributes: rc_this_oldid old_id associated with this entry (or zero) rc_last_oldid old_id associated with the entry before this one (or zero) rc_bot is bot, hidden + rc_ip IP address of the user in dotted quad notation rc_new obsolete, use rc_type==RC_NEW mExtra: @@ -82,7 +83,7 @@ class RecentChange # Writes the data in this object to the database function save() { - global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki; + global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki, $wgPutIPinRC; $fname = "RecentChange::save"; if ( !is_array($this->mExtra) ) { @@ -90,6 +91,10 @@ class RecentChange } $this->mExtra['lang'] = $wgLocalInterwiki; + if ( !$wgPutIPinRC ) { + $this->mAttribs['rc_ip'] = ''; + } + # Insert new row wfInsertArray( "recentchanges", $this->mAttribs, $fname ); @@ -126,12 +131,17 @@ class RecentChange # Makes an entry in the database corresponding to an edit /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, - $oldId, $lastTimestamp, $bot = "default" ) + $oldId, $lastTimestamp, $bot = "default", $ip = '' ) { if ( $bot == "default " ) { $bot = $user->isBot(); } + if ( !$ip ) { + global $wgIP; + $ip = empty( $wgIP ) ? '' : $wgIP; + } + $rc = new RecentChange; $rc->mAttribs = array( 'rc_timestamp' => $timestamp, @@ -149,6 +159,7 @@ class RecentChange 'rc_bot' => $bot ? 1 : 0, 'rc_moved_to_ns' => 0, 'rc_moved_to_title' => '', + 'rc_ip' => $ip, 'rc_new' => 0 # obsolete ); @@ -161,28 +172,34 @@ class RecentChange # Makes an entry in the database corresponding to page creation # Note: the title object must be loaded with the new id using resetArticleID() - /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default" ) + /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' ) { + if ( !$ip ) { + global $wgIP; + $ip = empty( $wgIP ) ? '' : $wgIP; + } if ( $bot == "default" ) { $bot = $user->isBot(); } + $rc = new RecentChange; $rc->mAttribs = array( - 'rc_timestamp' => $timestamp, - 'rc_cur_time' => $timestamp, - 'rc_namespace' => $title->getNamespace(), - 'rc_title' => $title->getDBkey(), - 'rc_type' => RC_NEW, - 'rc_minor' => $minor ? 1 : 0, - 'rc_cur_id' => $title->getArticleID(), - 'rc_user' => $user->getID(), - 'rc_user_text' => $user->getName(), - 'rc_comment' => $comment, - 'rc_this_oldid' => 0, - 'rc_last_oldid' => 0, - 'rc_bot' => $bot ? 1 : 0, - 'rc_moved_to_ns' => 0, - 'rc_moved_to_title' => '', + 'rc_timestamp' => $timestamp, + 'rc_cur_time' => $timestamp, + 'rc_namespace' => $title->getNamespace(), + 'rc_title' => $title->getDBkey(), + 'rc_type' => RC_NEW, + 'rc_minor' => $minor ? 1 : 0, + 'rc_cur_id' => $title->getArticleID(), + 'rc_user' => $user->getID(), + 'rc_user_text' => $user->getName(), + 'rc_comment' => $comment, + 'rc_this_oldid' => 0, + 'rc_last_oldid' => 0, + 'rc_bot' => $bot ? 1 : 0, + 'rc_moved_to_ns' => 0, + 'rc_moved_to_title' => '', + 'rc_ip' => $ip, 'rc_new' => 1 # obsolete ); @@ -194,8 +211,12 @@ class RecentChange } # Makes an entry in the database corresponding to a rename - /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment ) + /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) { + if ( !$ip ) { + global $wgIP; + $ip = empty( $wgIP ) ? '' : $wgIP; + } $rc = new RecentChange; $rc->mAttribs = array( 'rc_timestamp' => $timestamp, @@ -213,6 +234,7 @@ class RecentChange 'rc_bot' => $user->isBot() ? 1 : 0, 'rc_moved_to_ns' => $newTitle->getNamespace(), 'rc_moved_to_title' => $newTitle->getDBkey(), + 'rc_ip' => $ip, 'rc_new' => 0 # obsolete ); @@ -226,8 +248,12 @@ class RecentChange # A log entry is different to an edit in that previous revisions are # not kept - /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment ) + /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' ) { + if ( !$ip ) { + global $wgIP; + $ip = empty( $wgIP ) ? '' : $wgIP; + } $rc = new RecentChange; $rc->mAttribs = array( 'rc_timestamp' => $timestamp, @@ -245,6 +271,7 @@ class RecentChange 'rc_bot' => 0, 'rc_moved_to_ns' => 0, 'rc_moved_to_title' => '', + 'rc_ip' => $ip, 'rc_new' => 0 # obsolete ); $rc->mExtra = array( @@ -280,6 +307,7 @@ class RecentChange 'rc_bot' => 0, 'rc_moved_to_ns' => 0, 'rc_moved_to_title' => '', + 'rc_ip' => '', 'rc_new' => $row->cur_is_new # obsolete ); diff --git a/maintenance/indexes.sql b/maintenance/indexes.sql index ffa0782aeb..fa0359069e 100644 --- a/maintenance/indexes.sql +++ b/maintenance/indexes.sql @@ -51,7 +51,8 @@ ALTER TABLE recentchanges ADD INDEX rc_timestamp (rc_timestamp), ADD INDEX rc_namespace_title (rc_namespace, rc_title), ADD INDEX rc_cur_id (rc_cur_id), - ADD INDEX new_name_timestamp(rc_new,rc_namespace,rc_timestamp); + ADD INDEX new_name_timestamp(rc_new,rc_namespace,rc_timestamp), + ADD INDEX rc_ip (rc_ip); ALTER TABLE archive ADD KEY `name_title_timestamp` (`ar_namespace`,`ar_title`,`ar_timestamp`); diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 4f256c702f..fb8e578687 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -189,7 +189,8 @@ CREATE TABLE recentchanges ( rc_last_oldid int(10) unsigned NOT NULL default '0', rc_type tinyint(3) unsigned NOT NULL default '0', rc_moved_to_ns tinyint(3) unsigned NOT NULL default '0', - rc_moved_to_title varchar(255) binary NOT NULL default '' + rc_moved_to_title varchar(255) binary NOT NULL default '', + rc_ip char(15) NOT NULL default '' ) PACK_KEYS=1; CREATE TABLE watchlist ( diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 9f5b4a2bc9..8ed663be0c 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -134,6 +134,11 @@ function do_recentchanges_update() { dbsource( "maintenance/archives/patch-rc_type.sql" , $wgDatabase ); echo "ok\n"; } + if ( !$wgDatabase->fieldExists( "recentchanges", "rc_ip" ) ) { + echo "Adding rc_ip..."; + dbsource( "maintenance/archives/patch-rc_ip.sql", $wgDatabase ); + echo "ok\n"; + } } function do_user_real_name_update() { @@ -179,5 +184,4 @@ function do_categorylinks_update() { echo "ok\n"; } } - -?> \ No newline at end of file +?> -- 2.20.1